const axios = require('axios')
module.exports = {
  /*
  ** Headers of the page
  */
  head: {
    title: 'sbg-nuxt',
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: 'Nuxt.js project' }
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
    ]
  },
  /**
   * Cache
   */
  cache: {
    max: 1000,
    maxAge: 900000
  },
  generate: {
    routes: function () {
      return axios.get('http://47.100.6.170:3389/product/list')
        .then((res) => {
          return res.data.map((product) => {
            return '/product/' + product.product_id
          })
        })
    }
  },
  /*
  ** Customize the progress bar color
  */
  loading: { color: '#f9b233', failedColor: '#cc0000' },
  /*
  ** Build configuration
  */
  plugins: [
    { src: '~/plugins/swiper.js', ssr: false }
  ],
  css: [
    '~/assets/style/common.scss'
  ],
  build: {
    vendor: ['axios', 'babel-polyfill'],
    postcss: [
      require('autoprefixer')({
        browsers: ['last 3 versions']
      })
    ],
    /*
    ** Run ESLint on save
    */
    extend (config, ctx) {
      if (ctx.dev && ctx.isClient) {
        config.devtool = 'eval-source-map'
        config.module.rules.push({
          enforce: 'pre',
          test: /\.(js|vue)$/,
          loader: 'eslint-loader',
          exclude: /(node_modules)/
        })
      }
      const vueLoader = config.module.rules.find((rule) => rule.loader === 'vue-loader')
      vueLoader.options.loaders.sass = 'vue-style-loader!css-loader!sass-loader'
    }
  }
}
